﻿namespace IPTableAdapters
{
    using System;
    using System.CodeDom.Compiler;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Configuration;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using System.Diagnostics;

    [DesignerCategory("code"), HelpKeyword("vs.data.TableAdapter"), DataObject(true), Designer("Microsoft.VSDesigner.DataSource.Design.TableAdapterDesigner, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), GeneratedCode("System.Data.Design.TypedDataSetGenerator", "2.0.0.0"), ToolboxItem(true)]
    public class CountryTableAdapter : Component
    {
        private SqlDataAdapter _adapter;
        private bool _clearBeforeFill;
        private SqlCommand[] _commandCollection;
        private SqlConnection _connection;

        /*[DebuggerNonUserCode]*/
        public CountryTableAdapter()
        {
            this.ClearBeforeFill = true;
        }

        [DebuggerNonUserCode, DataObjectMethod(DataObjectMethodType.Delete, true), HelpKeyword("vs.data.TableAdapter")]
        public virtual int Delete(bool IsDelete, string DeleteBy, string DeleteIP, string Original_Country)
        {
            int ret;

            this.Adapter.DeleteCommand.Parameters[0].Value = IsDelete;

            if (DeleteBy == null)
            {
                throw new ArgumentNullException("DeleteBy");
            }
            this.Adapter.DeleteCommand.Parameters[1].Value = DeleteBy;

            if (DeleteIP == null)
            {
                this.Adapter.DeleteCommand.Parameters[2].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.DeleteCommand.Parameters[2].Value = DeleteIP;
            }

            if (Original_Country == null)
            {
                throw new ArgumentNullException("Original_Country");
            }
            this.Adapter.DeleteCommand.Parameters[3].Value = Original_Country;
            ConnectionState previousConnectionState = this.Adapter.DeleteCommand.Connection.State;
            if ((this.Adapter.DeleteCommand.Connection.State & ConnectionState.Open) != ConnectionState.Open)
            {
                this.Adapter.DeleteCommand.Connection.Open();
            }
            try
            {
                ret = this.Adapter.DeleteCommand.ExecuteNonQuery();
            }
            finally
            {
                if (previousConnectionState == ConnectionState.Closed)
                {
                    this.Adapter.DeleteCommand.Connection.Close();
                }
            }
            return ret;
        }

        [DataObjectMethod(DataObjectMethodType.Select, true), DebuggerNonUserCode, HelpKeyword("vs.data.TableAdapter")]
        public virtual IP.CountryDataTable GetCountryData()
        {
            this.Adapter.SelectCommand = this.CommandCollection[0];
            IP.CountryDataTable dataTable = new IP.CountryDataTable();
            this.Adapter.Fill(dataTable);
            return dataTable;
        }

        /*[DebuggerNonUserCode]*/
        private void InitAdapter()
        {
            this._adapter = new SqlDataAdapter();
            DataTableMapping tableMapping = new DataTableMapping();
            tableMapping.SourceTable = "Table";
            tableMapping.DataSetTable = "Country";
            tableMapping.ColumnMappings.Add("Country", "Country");
            tableMapping.ColumnMappings.Add("EnglishName", "EnglishName");
            tableMapping.ColumnMappings.Add("ChineseName", "ChineseName");
            tableMapping.ColumnMappings.Add("CreateBy", "CreateBy");
            tableMapping.ColumnMappings.Add("CreateDate", "CreateDate");
            tableMapping.ColumnMappings.Add("UpdateBy", "UpdateBy");
            tableMapping.ColumnMappings.Add("UpdateDate", "UpdateDate");
            tableMapping.ColumnMappings.Add("OwnerGroupID", "OwnerGroupID");
            tableMapping.ColumnMappings.Add("PCTYN", "PCTYN");
            tableMapping.ColumnMappings.Add("CreateIP", "CreateIP");
            tableMapping.ColumnMappings.Add("UpdateIP", "UpdateIP");
            tableMapping.ColumnMappings.Add("IsDelete", "IsDelete");
            tableMapping.ColumnMappings.Add("DeleteBy", "DeleteBy");
            tableMapping.ColumnMappings.Add("DeleteIP", "DeleteIP");
            
            this._adapter.TableMappings.Add(tableMapping);
            this._adapter.DeleteCommand = new SqlCommand();
            this._adapter.DeleteCommand.Connection = this.Connection;
            //this._adapter.DeleteCommand.CommandText = "DELETE FROM [Country] WHERE (([Country] = @Original_Country))";
            this._adapter.DeleteCommand.CommandText = "UPDATE [Country] SET IsDelete = @IsDelete,DeleteBy = @DeleteBy,DeleteDate = GETDATE(), DeleteIP = @DeleteIP WHERE (([Country] = @Original_Country))";
            this._adapter.DeleteCommand.CommandType = CommandType.Text;
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@IsDelete", SqlDbType.Bit, 1, ParameterDirection.Input, 0, 0, "IsDelete", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@DeleteBy", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "DeleteBy", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@DeleteIP", SqlDbType.NVarChar, 50, ParameterDirection.Input, 0, 0, "DeleteIP", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.DeleteCommand.Parameters.Add(new SqlParameter("@Original_Country", SqlDbType.NVarChar, 0, ParameterDirection.Input, 0, 0, "Country", DataRowVersion.Original, false, null, "", "", ""));
            this._adapter.InsertCommand = new SqlCommand();
            this._adapter.InsertCommand.Connection = this.Connection;
            this._adapter.InsertCommand.CommandText = "INSERT INTO Country\r\n                      (Country, EnglishName, ChineseName, PCTYN, CreateBy, UpdateBy, OwnerGroupID, CreateIP)\r\nVALUES     (@Country,@EnglishName,@ChineseName,@PCTYN,@CreateBy,@UpdateBy,@OwnerGroupID, @CreateIP)";
            this._adapter.InsertCommand.CommandType = CommandType.Text;
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@Country", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "Country", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@EnglishName", SqlDbType.NVarChar, 200, ParameterDirection.Input, 0, 0, "EnglishName", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@ChineseName", SqlDbType.NVarChar, 200, ParameterDirection.Input, 0, 0, "ChineseName", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@PCTYN", SqlDbType.Bit, 1, ParameterDirection.Input, 0, 0, "PCTYN", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@CreateBy", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "CreateBy", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@UpdateBy", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "UpdateBy", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@OwnerGroupID", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "OwnerGroupID", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new SqlParameter("@CreateIP", SqlDbType.NVarChar, 50, ParameterDirection.Input, 0, 0, "CreateIP", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand = new SqlCommand();
            this._adapter.UpdateCommand.Connection = this.Connection;
            this._adapter.UpdateCommand.CommandText = "UPDATE    Country\r\nSET              EnglishName = @EnglishName, ChineseName = @ChineseName, UpdateBy = @UpdateBy, PCTYN = @PCTYN, UpdateIP = @UpdateIP  \r\nWHERE     (Country = @Original_Country)";
            this._adapter.UpdateCommand.CommandType = CommandType.Text;
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@EnglishName", SqlDbType.NVarChar, 200, ParameterDirection.Input, 0, 0, "EnglishName", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@ChineseName", SqlDbType.NVarChar, 200, ParameterDirection.Input, 0, 0, "ChineseName", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@UpdateBy", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "UpdateBy", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@PCTYN", SqlDbType.Bit, 1, ParameterDirection.Input, 0, 0, "PCTYN", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@UpdateIP", SqlDbType.NVarChar, 50, ParameterDirection.Input, 0, 0, "UpdateIP", DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand.Parameters.Add(new SqlParameter("@Original_Country", SqlDbType.NVarChar, 60, ParameterDirection.Input, 0, 0, "Country", DataRowVersion.Original, false, null, "", "", ""));
        }

        /*[DebuggerNonUserCode]*/
        private void InitCommandCollection()
        {
            this._commandCollection = new SqlCommand[] { new SqlCommand() };
            this._commandCollection[0].Connection = this.Connection;
            this._commandCollection[0].CommandText = "SELECT Country, EnglishName, ChineseName, PCTYN, CreateBy, CreateDate, UpdateBy, UpdateDate, OwnerGroupID,IsDelete FROM Country WHERE IsDelete = 0 Union Select '', '', '', '', '', getdate(), '', getdate(), 0, 0";
            this._commandCollection[0].CommandType = CommandType.Text;
        }

        /*[DebuggerNonUserCode]*/
        private void InitConnection()
        {
            this._connection = new SqlConnection();
            this._connection.ConnectionString = ConfigurationManager.ConnectionStrings["LocalSqlConnection1"].ConnectionString;
        }

        [DataObjectMethod(DataObjectMethodType.Insert, true), DebuggerNonUserCode, HelpKeyword("vs.data.TableAdapter")]
        public virtual int Insert(string Country, string EnglishName, string ChineseName, bool PCTYN, string CreateBy, string UpdateBy, string OwnerGroupID, string CreateIP)
        {
            int ret;
            if (Country == null)
            {
                throw new ArgumentNullException("Country");
            }
            this.Adapter.InsertCommand.Parameters[0].Value = Country;
            if (EnglishName == null)
            {
                this.Adapter.InsertCommand.Parameters[1].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[1].Value = EnglishName;
            }
            if (ChineseName == null)
            {
                this.Adapter.InsertCommand.Parameters[2].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[2].Value = ChineseName;
            }
            this.Adapter.InsertCommand.Parameters[3].Value = PCTYN;
            if (CreateBy == null)
            {
                throw new ArgumentNullException("CreateBy");
            }
            this.Adapter.InsertCommand.Parameters[4].Value = CreateBy;
            if (UpdateBy == null)
            {
                throw new ArgumentNullException("UpdateBy");
            }
            this.Adapter.InsertCommand.Parameters[5].Value = UpdateBy;
            if (OwnerGroupID == null)
            {
                throw new ArgumentNullException("OwnerGroupID");
            }
            this.Adapter.InsertCommand.Parameters[6].Value = OwnerGroupID;

            if (CreateIP == null)
            {
                this.Adapter.InsertCommand.Parameters[7].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.InsertCommand.Parameters[7].Value = CreateIP;
            }

            ConnectionState previousConnectionState = this.Adapter.InsertCommand.Connection.State;
            if ((this.Adapter.InsertCommand.Connection.State & ConnectionState.Open) != ConnectionState.Open)
            {
                this.Adapter.InsertCommand.Connection.Open();
            }
            try
            {
                ret = this.Adapter.InsertCommand.ExecuteNonQuery();
            }
            finally
            {
                if (previousConnectionState == ConnectionState.Closed)
                {
                    this.Adapter.InsertCommand.Connection.Close();
                }
            }
            return ret;
        }

        [DebuggerNonUserCode, HelpKeyword("vs.data.TableAdapter")]
        public virtual int Update(IP dataSet)
        {
            return this.Adapter.Update(dataSet, "Country");
        }

        [DebuggerNonUserCode, HelpKeyword("vs.data.TableAdapter")]
        public virtual int Update(DataRow[] dataRows)
        {
            return this.Adapter.Update(dataRows);
        }

        [DebuggerNonUserCode, HelpKeyword("vs.data.TableAdapter")]
        public virtual int Update(IP.CountryDataTable dataTable)
        {
            return this.Adapter.Update(dataTable);
        }

        [DebuggerNonUserCode, HelpKeyword("vs.data.TableAdapter")]
        public virtual int Update(DataRow dataRow)
        {
            return this.Adapter.Update(new DataRow[] { dataRow });
        }

        [DataObjectMethod(DataObjectMethodType.Update, true), DebuggerNonUserCode, HelpKeyword("vs.data.TableAdapter")]
        public virtual int Update(string EnglishName, string ChineseName, string UpdateBy, bool PCTYN, string UpdateIP, string Original_Country)
        {
            int ret;
            if (EnglishName == null)
            {
                this.Adapter.UpdateCommand.Parameters[0].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[0].Value = EnglishName;
            }
            if (ChineseName == null)
            {
                this.Adapter.UpdateCommand.Parameters[1].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[1].Value = ChineseName;
            }
            if (UpdateBy == null)
            {
                throw new ArgumentNullException("UpdateBy");
            }
            this.Adapter.UpdateCommand.Parameters[2].Value = UpdateBy;
            this.Adapter.UpdateCommand.Parameters[3].Value = PCTYN;

            if (UpdateIP == null)
            {
                this.Adapter.UpdateCommand.Parameters[4].Value = DBNull.Value;
            }
            else
            {
                this.Adapter.UpdateCommand.Parameters[4].Value = UpdateIP;
            }

            if (Original_Country == null)
            {
                throw new ArgumentNullException("Original_Country");
            }
            this.Adapter.UpdateCommand.Parameters[5].Value = Original_Country;
            ConnectionState previousConnectionState = this.Adapter.UpdateCommand.Connection.State;
            if ((this.Adapter.UpdateCommand.Connection.State & ConnectionState.Open) != ConnectionState.Open)
            {
                this.Adapter.UpdateCommand.Connection.Open();
            }
            try
            {
                ret = this.Adapter.UpdateCommand.ExecuteNonQuery();
            }
            finally
            {
                if (previousConnectionState == ConnectionState.Closed)
                {
                    this.Adapter.UpdateCommand.Connection.Close();
                }
            }
            return ret;
        }

        /*[DebuggerNonUserCode]*/
        private SqlDataAdapter Adapter
        {
            get
            {
                if (this._adapter == null)
                {
                    this.InitAdapter();
                }
                return this._adapter;
            }
        }

        /*[DebuggerNonUserCode]*/
        public bool ClearBeforeFill
        {
            get
            {
                return this._clearBeforeFill;
            }
            set
            {
                this._clearBeforeFill = value;
            }
        }

        /*[DebuggerNonUserCode]*/
        protected SqlCommand[] CommandCollection
        {
            get
            {
                if (this._commandCollection == null)
                {
                    this.InitCommandCollection();
                }
                return this._commandCollection;
            }
        }

        /*[DebuggerNonUserCode]*/
        internal SqlConnection Connection
        {
            get
            {
                if (this._connection == null)
                {
                    this.InitConnection();
                }
                return this._connection;
            }
            set
            {
                this._connection = value;
                if (this.Adapter.InsertCommand != null)
                {
                    this.Adapter.InsertCommand.Connection = value;
                }
                if (this.Adapter.DeleteCommand != null)
                {
                    this.Adapter.DeleteCommand.Connection = value;
                }
                if (this.Adapter.UpdateCommand != null)
                {
                    this.Adapter.UpdateCommand.Connection = value;
                }
                for (int i = 0; i < this.CommandCollection.Length; i++)
                {
                    if (this.CommandCollection[i] != null)
                    {
                        this.CommandCollection[i].Connection = value;
                    }
                }
            }
        }
    }
}

